package cn.middle.remote.handler.netty;

import cn.middle.remote.handler.client.ClientProcessingHandler;
import cn.middle.remote.message.BaseSignal;
import io.netty.channel.ChannelHandlerContext;

public class UserHandler extends BaseHandler<BaseSignal> {
	
	
	private ClientProcessingHandler<?> processHandler;
	
	public UserHandler(ClientProcessingHandler<?> processHandler) {
		this.processHandler = processHandler;
		
	}

	@Override
	public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
		processHandler.userEventTriggered(ctx, evt);
		super.userEventTriggered(ctx, evt);
	}
	
	
	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		processHandler.channelActive(ctx);
		super.channelActive(ctx);
	}
	
	/**
	 * 断开
	 */
	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		processHandler.channelInactive(ctx);
		super.channelInactive(ctx);
	}
	
	/**
	 * 发生异常
	 */
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		processHandler.exceptionCaught(ctx, cause);
		super.exceptionCaught(ctx, cause);
	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, BaseSignal msg) throws Exception {
		processHandler.received(ctx, msg);
		
	}

}
